<?php

/*
 * litchicms
 * Copyright (C) 2010-7-19 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");
require 'main.fun.php';
$Db = openSQL();


// $SET['attachment_right'] 是否开启附件权限
$attachment_right = false; //假设无需权限

if ($attachment_right) {
    return;
}
//
$attachment_id = intval($RT['v']['attach']);

if ($attachment_id == 0) {
    msg("参数错误");
}

ob_clean();
$one_attach = brk_select_one('attachment', '*', "WHERE attach_id=" . $attachment_id);
if (!$one_attach) {
    msg("没有该附件");
}


/*
  array(14) {
  ["attach_id"] => string(3) "131"
  ["attach_type"] => string(4) ".rar"
  ["attach_sys_suffix"] => string(7) ".attach"
  ["attach_sys_name"] => string(22) "127953694966052.attach"
  ["attach_name"] => string(4) "6.24"
  ["attach_time"] => string(10) "1279536949"
  ["attach_user"] => string(1) "1"
  ["attach_isimg"] => string(1) "0"
  ["attach_size"] => string(7) "1153960"
  ["attach_path"] => string(35) "data/tt/10/7/127953694966052.attach"
  ["attach_sys_thumb"] => string(25) "data/sys/attach_40_40.jpg"
  ["attach_thumb"] => string(25) "data/sys/attach_20_20.jpg"
  ["attach_right"] => string(1) "0"
  ["attach_click"] => string(1) "0"
  }
 */
$mimetype = require SYSTEM . 'data/mimetype.array.php';
//if (array_key_exists($one_attach['attach_type'], $mimetype)) {
//    header('Content-type: ' . $mimetype[$one_attach['attach_type']]);
//} else {
//    header('Content-type: application/octet-stream');
//}
header('Content-Disposition: attachment; filename="' . str_replace("+", "%20", urlencode($one_attach['attach_name'])) . $one_attach['attach_type'] . '"');
readfile(BRK . $one_attach['attach_path']);
exit();